import axios from 'axios'

export const httpGet = ({ url, params = null }) => {
  return axios({
    method: 'GET',
    params,
    url
  }).then(res => [res, null]).catch(err => {
    console.log('报错啦')
    for (let i in err) {
      console.log(i, err[i])
    }
    return [null, err.response.data]
  })
}

export const httpPost = ({ url, data = null }) => {
  return axios({
    method: 'POST',
    data,
    url
  }).then(res => [res, null]).catch(err => {
    console.log('报错啦')
    // for (let i in err) {
    //   console.log(i, err[i])
    // }
    return [null, err.response.data]
  })
}

export const httpPut = ({ url, data = null }) => {
  return axios({
    method: 'PUT',
    data, url
  }).then(res => [res, null]).catch(err => {
    console.log('报错啦')
    // for (let i in err) {
    //   console.log(i, err[i])
    // }
    return [null, err.response.data]
  })
}

export const httpDelete = ({ url, params = null }) => {
  return axios({
    method: 'DELETE',
    url, params
  }).then(res => [res, null]).catch(err => {
    console.log('报错啦')
    // for (let i in err) {
    //   console.log(i, err[i])
    // }
    return [null, err.response.data]
  })
}
